const app = getApp()
import trigger from '../../utils/util.js'
Page({
	data: {
		resourceDomain: app.resourceDomain,
    isShow: false
	},
	onLoad: function(options) {
    // (trigger.trigger)(this,'../Medical/detail', '','',options.id)
    app.updateFlag(this)
		var that = this;
		app.request(app.apiDomain + "index.php?c=health&a=detail", {
			id : options.id
		}, function(res) {
			that.setData({
				news_detail: res.data.data,
			});
			wx.setNavigationBarTitle({
				title: res.data.data.f_title,
			})
			var WxParse = require('../../wxParse/wxParse.js');
			wx.setStorageSync('title', res.data.data.f_title);
			var article = res.data.data.f_content;
			WxParse.wxParse('article', 'html', article, that, 0);
		});
		
		app.request(app.apiDomain + "index.php?c=health&a=likeusers", {
			id:options.id,
			page:1,
			size:6
		}, function(res) {
			console.log(res.data.data.list.length)
			if(res.data.data.list.length == 0){
				var a = false;
 			}else{
				var a = true;
			}
			that.setData({
				img_list:res.data.data.list,
				img_get:a
			})
		});
		
	},
  authSuccess(e) {
    this.setData({
      isShow: false
    })
  },
  authFail(e) {
    this.setData({
      isShow: false
    })
  },
  click() {
    this.setData({
      isShow: false
    })
  },
  // getUserInfo: function () {
  //   var that = this
  //   if (app.getUserInfo(that)) {
  //     that.setData({
  //       user_auth: false
  //     })
  //   }
  // },
	zan_click:function (e) {
		var that = this;
    if (!app.isAuth) {
      that.setData({
        isShow: true
      })
    } else {
        that.setData({
          zan_fl: 'on',
          img_get: true,
          ["news_detail.f_like_num"]: parseFloat(that.data.news_detail.f_like_num) + 1
        })
        app.request(app.apiDomain + "index.php?c=user&a=like", {
          id: e.currentTarget.dataset.id,
          type: 'health'
        }, function (res) {
          var a = {};
          a.icon = wx.getStorageSync('icon')
          if (that.data.img_list.length < 6 || that.data.img_list == '[]') {
            that.data.img_list.unshift(a)
          } else {
            that.data.img_list.unshift(a)
            that.data.img_list.splice(6, 1, '')
          }
          that.setData({
            img_list: that.data.img_list
          });
          // console.log(that.data.img_list,123)
        });
      }
			
		},
  return_act() {
    let pages = getCurrentPages()
    if (pages.length == 1) {
      wx.reLaunch({
        url: '../Medical/index',
      })
    } else {
      wx.navigateBack({
        
      })
    }
  },
  return_index() {
    wx.reLaunch({
      url: '../index/index',
    })
  },
    onReady() {
      app.SystemInfo(this)
    },
	onShareAppMessage: function() {
		var nickName = '';
		var title = '';
		try {
			nickName = wx.getStorageSync('nickName');
			title = wx.getStorageSync('title');
	
		} catch (e) {
			// Do something when catch error
		}
		return {
			title: nickName + '推荐你阅读"' + title + '"'
		}
	},
})